package cn.iocoder.yudao.module.blog.convert.postlike;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.blog.controller.app.post.likevo.AppBlogPostLikeRespVO;
import cn.iocoder.yudao.module.blog.convert.base.BlogConvert;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.blog.controller.admin.postlike.vo.*;
import cn.iocoder.yudao.module.blog.dal.dataobject.postlike.BlogPostLikeDO;

/**
 * 帖子点赞 Convert
 *
 * @author 曹建伟
 */
@Mapper
public interface BlogPostLikeConvert {

    BlogPostLikeConvert INSTANCE = Mappers.getMapper(BlogPostLikeConvert.class);

    BlogPostLikeDO convert(BlogPostLikeCreateReqVO bean);

    BlogPostLikeDO convert(BlogPostLikeUpdateReqVO bean);

    BlogPostLikeRespVO convert(BlogPostLikeDO bean);

    List<BlogPostLikeRespVO> convertList(List<BlogPostLikeDO> list);

    PageResult<BlogPostLikeRespVO> convertPage(PageResult<BlogPostLikeDO> page);

    List<BlogPostLikeExcelVO> convertList02(List<BlogPostLikeDO> list);

    default AppBlogPostLikeRespVO convertApp(BlogPostLikeDO bean, MemberUserRespDTO memberUserRespDTO){
        if ( bean == null ) {
            return null;
        }

        AppBlogPostLikeRespVO appBlogPostLikeRespVO = new AppBlogPostLikeRespVO();

        appBlogPostLikeRespVO.setMember(BlogConvert.INSTANCE.covnertMember(memberUserRespDTO));
        appBlogPostLikeRespVO.setPostId(bean.getPostId());
        appBlogPostLikeRespVO.setId(bean.getId());
        appBlogPostLikeRespVO.setMemberId(bean.getMemberId());
        appBlogPostLikeRespVO.setCreateTime(bean.getCreateTime());

        return appBlogPostLikeRespVO;
    }

    default List<AppBlogPostLikeRespVO> convertAppList(List<BlogPostLikeDO> blogPostLikeDOList, Map<Long, MemberUserRespDTO> memberMap){
        List<AppBlogPostLikeRespVO> list = new ArrayList<>();
        blogPostLikeDOList.forEach(blogPostLikeDO -> {
            list.add(convertApp(blogPostLikeDO, memberMap.get(blogPostLikeDO.getMemberId())));
        });

        return list;
    }
    default PageResult<AppBlogPostLikeRespVO> convertAppPage(PageResult<BlogPostLikeDO> page, Map<Long, MemberUserRespDTO> memberMap ){
        if ( page == null ) {
            return null;
        }

        PageResult<AppBlogPostLikeRespVO> pageResult = new PageResult<AppBlogPostLikeRespVO>();
        List<AppBlogPostLikeRespVO> list = convertAppList(page.getList(), memberMap);

        pageResult.setList(list);
        pageResult.setTotal(page.getTotal());

        return pageResult;
    }
}
